<?php

if (!defined("JOYEASY"))
    exit("Access Denied");

class IndexAction extends BaseAction {

    public function index() {
        $this->assign('bcid', 0); //顶级栏目 
        $this->display();
    }
	function jiamengshenqing(){
		if($_POST['title']=='' || $_POST['chuanzhen']=='' || $_POST['dianhua']==''){
            $this->error("带*号为必填项");
			
		}else{
			$jiameng=M('jiameng');
			$_POST['createtime']=time();
			$_POST['status']=1;
			$_POST['userid']=1;
			$_POST['lang']=1;
			if($jiameng->add($_POST)){
				$this->success("提交成功");
			}else{
				$this->error("提交失败");
			}
		}
		
	}
	function ziliaoxiazai(){
		if($_POST['title']=='' || $_POST['youxiang']=='' || $_POST['dianhua']==''){
            $this->error("带*号为必填项");
			
		}else{
			$jiameng=M('xiazai');
			$_POST['createtime']=time();
			$_POST['status']=1;
			$_POST['userid']=1;
			$_POST['lang']=1;
			if($jiameng->add($_POST)){
				$this->success("提交成功");
			}else{
				$this->error("提交失败");
			}
		}
		
	}
	function hahahhairen(){
		$aa=rename("Cache/Data","Cache/Data2014");
		var_dump($aa);
		if($aa){
			$this->success("提交成功");
		}else{
			$this->error("提交失败");
		}
		
	}

    function about_user() {
        $all_article = 0;
        $all_guest = 0;
        $all_com = 0;
        $userid = $_GET['userid'];
        $user = M("User");
        $userinfo = $user->where('id = ' . $userid)->find(); //作者信息
        $article = M("Article");
        $count = $article->where('status = 1 and userid = ' . $userid)->count();
        if ($count) {
            import("@.ORG.Page");
            $listRows = !empty($cat['pagesize']) ? $cat['pagesize'] : C('PAGE_LISTROWS');
            $page = new Page($count, $listRows);
            $pages = $page->show();
            $list = $article->where('status = 1 and userid = ' . $userid)->limit($page->firstRow . ',' . $page->listRows)->select(); //作者文章
            if (!empty($list)) {
                $avatar = M("Comment");
                foreach ($list as $key => $all) {
                    $list[$key]['com_num'] = $avatar->where('status = 1 and article_id = ' . $all['id'])->count();
                }
            }
            $this->assign('list', $list);
            $this->assign('pages', $pages);
        }
        $all_article = $article->where('status = 1 and userid = ' . $userid)->count();
        $com = M("Comment");
        $all_com = $com->where('status = 1 and userid =' . $userid)->count(); //作者评论
        $guest = M("Guestbook");
        $all_guest = $guest->where('status = 1 and user =' . $userid)->count(); //作者评论
        $this->assign('userinfo', $userinfo);
        $this->assign('all_article', $all_article);
        $this->assign('all_com', $all_com);
        $this->assign('all_guest', $all_guest);
        $this->display();
    }

    function about_com() {
        $all_article = 0;
        $all_guest = 0;
        $all_com = 0;
        $userid = $_GET['userid'];
        $user = M("User");
        $userinfo = $user->where('id = ' . $userid)->find(); //作者信息
        $article = M("Article");
        $all_article = $article->where('status = 1 and userid = ' . $userid)->count();
        $com = M("Comment");
        $all_com = $com->where('status = 1 and userid =' . $userid)->count(); //作者评论
        $count = $com->where('status = 1 and userid = ' . $userid)->count();
        if ($count) {
            import("@.ORG.Page");
            $listRows = !empty($cat['pagesize']) ? $cat['pagesize'] : C('PAGE_LISTROWS');
            $page = new Page($count, $listRows);
            $pages = $page->show();
            $list = $com->where('status = 1 and userid = ' . $userid)->limit($page->firstRow . ',' . $page->listRows)->select(); //作者文章
            $this->assign('list', $list);
            $this->assign('pages', $pages);
        }
        $list = $com->where('status = 1 and userid = ' . $userid)->select(); //作者评论
        $guest = M("Guestbook");
        $all_guest = $guest->where('status = 1 and user =' . $userid)->count(); //作者评论
        $this->assign('userinfo', $userinfo);
        $this->assign('all_article', $all_article);
        $this->assign('all_com', $all_com);
        $this->assign('all_guest', $all_guest);
        $this->display();
    }

    function about_guest() {
        $userid = $_GET['userid'];
        $all_article = 0;
        $all_guest = 0;
        $all_com = 0;
        $user = M("User");
        $userinfo = $user->where('id = ' . $userid)->find(); //作者信息
        $article = M("Article");
        $all_article = $article->where('status = 1 and userid = ' . $userid)->count();
        $com = M("Comment");
        $all_com = $com->where('status = 1 and userid =' . $userid)->count(); //作者评论
        $guest = M("Guestbook");
        $all_guest = $guest->where('status = 1 and user =' . $userid)->count(); //所有留言数
        $count = $guest->where('status = 1 and user = ' . $userid)->count();
        if ($count) {
            import("@.ORG.Page");
            $listRows = !empty($cat['pagesize']) ? $cat['pagesize'] : C('PAGE_LISTROWS');
            $page = new Page($count, $listRows);
            $pages = $page->show();
            $field = $field ? $field : 'u.avatar as avatar,u.username as name,u.id as id ,zx_guestbook.content as content,zx_guestbook.createtime as createtime';
            $list = $guest->join('`zx_user` as `u` on u.username =zx_guestbook.username')->where('zx_guestbook.user =' . $userid . ' and zx_guestbook.status = 1')->order('listorder desc,zx_guestbook.id desc')->field($field)->limit($page->firstRow . ',' . $page->listRows)->select();

            $this->assign('list', $list);
            $this->assign('pages', $pages);
        }
        $this->assign('userinfo', $userinfo);
        $this->assign('all_article', $all_article);
        $this->assign('all_com', $all_com);
        $this->assign('all_guest', $all_guest);
        $this->assign('moduleid', 8);
        $this->display();
    }

}

?>